package com.frank.activedatabus.dispatch;

import com.frank.activedatabus.utils.ThreadUtils;
import ohos.eventhandler.EventHandler;

/**
 * @version 1.0.1
 * @description:主线程分发器
 * @program: activedatatest
 * @Author xiaozhijun
 * @Date 2020/03/15 10:25
 */
public class MainDispatch implements IDispatch {


    EventHandler mainHandler;

    MainDispatch(EventHandler main) {
        this.mainHandler = main;
    }

    @Override
    public synchronized void post(Runnable task) {
        if (!ThreadUtils.isMainThread()) {
            if (mainHandler != null) {
                mainHandler.postSyncTask(task);
            }
        } else {
            task.run();
        }
    }

}
